import java.util.concurrent.*;
class MyThreadPool{
    private BlockingQueue<Runnable> queue = new ArrayBlockingQueue<>(10);
    public void submit(Runnable runnable) throws InterruptedException {
        queue.put(runnable);
    }
    public MyThreadPool(int n){
        for (int i = 0; i < n; i++) {
            Thread t = new Thread(()->{
                try {
                    queue.take().run();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });
            t.start();
        }
    }

}

public class Test1 {
    public static void main(String[] args) throws InterruptedException {
        MyThreadPool pool = new MyThreadPool(5);
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(1);
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(2);
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(3);
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(4);
            }
        });
        pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(5);
            }
        }); pool.submit(new Runnable() {
            @Override
            public void run() {
                System.out.println(6);
            }
        });
    }
}
